﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 药品信息管理
{
    public partial class YP_CRKLX : Form
    {
        public YP_CRKLX()
        {
            InitializeComponent();
        }

        private void YP_CRKLX_Load(object sender, EventArgs e)
        {
            db db1 = new db();
            string str = (@"SELECT  BM 编码, DH 代号, MC 入出库类型  FROM  YK_CRLX order by bm");
            //string str =( @"select * from YK_CRLX order by bm");
            dataGridViewX1.DataSource = db1.sqldt(str);
        }


        private void buttonItem1_Click(object sender, EventArgs e)
        {

            db db1 = new db();
            if (textBox1.Text == "")
            {
                MessageBox.Show("编码不能为空！请输入编码再保存！");
                return;
            }
            else
            {
                string sqlcount = db1.sqlstr("select count(*) from yk_crlx where bm = '" + textBox1.Text + "'");
                if (sqlcount != "0")
                { MessageBox.Show("编码重复!请重新填写编码再保存"); }
                else
                {
                    
                    db1.sqlcmd(@"insert  into YK_CRLX (bm,dh,mc)  values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')");
                    MessageBox.Show("保存成功");
                    YP_CRKLX_Load(sender, e);
                }
            }
            
        }

        private void buttonItem2_Click(object sender, EventArgs e)
        {
            db db1 = new db();
            db1.sqlcmd(@"update YK_CRLX set dh='" + textBox2.Text + "',mc='" + textBox3.Text + "' where bm='" + dataGridViewX1.CurrentRow.Cells[0].Value.ToString() + "'");
            MessageBox.Show("更新成功");
            YP_CRKLX_Load(sender, e);
        }

        private void buttonItem3_Click(object sender, EventArgs e)
        {
            db db1 = new db();
            if (MessageBox.Show("确定要删除该类型信息吗？", "删除提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                db1.sqlcmd(@"delete from YK_CRLX where bm='" + dataGridViewX1.CurrentRow.Cells[0].Value.ToString() + "'");
            }
            YP_CRKLX_Load(sender,e);
        }

        private void dataGridViewX1_Click(object sender, EventArgs e)
        {
            textBox1.Text = Convert.ToString(dataGridViewX1[0, dataGridViewX1.CurrentCell.RowIndex].Value).Trim();
            textBox2.Text = Convert.ToString(dataGridViewX1[1, dataGridViewX1.CurrentCell.RowIndex].Value).Trim();
            textBox3.Text = Convert.ToString(dataGridViewX1[2, dataGridViewX1.CurrentCell.RowIndex].Value).Trim();
        }
    }
}